package com.hyk.service.impl;

import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.hyk.domain.Coin;
import com.hyk.service.CoinService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyk.domain.CoinConfig;
import com.hyk.mapper.CoinConfigMapper;
import com.hyk.service.CoinConfigService;

import javax.annotation.Resource;

@Service
public class CoinConfigServiceImpl extends ServiceImpl<CoinConfigMapper, CoinConfig> implements CoinConfigService{

    @Resource
    private CoinService coinService;

    @Override
    public boolean saveOrUpdateConfig(CoinConfig coinConfig) {
        Coin coin = coinService.getById(coinConfig.getId());
        if (coin == null){
            throw new ApiException("coin_id错误");
        }
        coinConfig.setName(coin.getName());
        coinConfig.setCoinType(coin.getType());
        saveOrUpdate(coinConfig);
        return true;
    }
}
